package pers.bbw.crr.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pers.bbw.crr.dto.EquipmentSearchDto;
import pers.bbw.crr.entity.Equipment;
import pers.bbw.crr.service.EquipmentService;
import pers.bbw.crr.util.AjaxResult;

import javax.annotation.Resource;

/**
 * 器材信息控制器
 *
 * @author bbw
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/equipment")
@Api(tags = "器材信息控制器")
public class EquipmentController {

    @Resource
    private EquipmentService equipmentService;

    /**
     * 查询器材列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表", notes = "分页查询")
    public AjaxResult list(@ApiParam(value = "器材信息searchDto") EquipmentSearchDto dto) {
        PageInfo<Equipment> equipmentPageInfo = equipmentService.selectEquipmentList(dto);
        return AjaxResult.success(equipmentPageInfo);
    }

    /**
     * 获取器材详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详情", notes = "根据id查询")
    public AjaxResult getInfo(@ApiParam(value = "器材id") @PathVariable("id") int id) {
        return AjaxResult.success(equipmentService.selectEquipmentById(id));
    }

    /**
     * 新增器材
     */
    @PostMapping
    @ApiOperation(value = "新增")
    public AjaxResult add(@ApiParam(value = "器材实体类对象") @RequestBody Equipment equipment, MultipartFile file) {
        equipmentService.insertEquipment(equipment, file);
        return AjaxResult.success();
    }

    /**
     * 修改器材
     */
    @PutMapping
    @ApiOperation(value = "修改")
    public AjaxResult edit(@ApiParam(value = "器材实体类对象") @RequestBody Equipment equipment, MultipartFile file) {
        equipmentService.updateEquipment(equipment, file);
        return AjaxResult.success();
    }

    /**
     * 删除器材
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "批量删除")
    public AjaxResult remove(@ApiParam(value = "器材id数组") @PathVariable int[] ids) {
        return AjaxResult.success(equipmentService.deleteEquipmentByIds(ids));
    }

}
